package com.his.diagnose.service.Imp;

import com.his.diagnose.dao.DiagnosisresultMapper;
import com.his.diagnose.entity.Diagnosisresult;
import com.his.diagnose.service.DiagnosisResultService;
import com.his.diagnose.vo.DiagnosisVo;
import com.his.diagnose.vo.DiagnosisresultVo;
import com.his.diagnose.vo.GetDiagnosisVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.exception.HisExecption;
import com.xiao.common.util.BeanUtil;
import com.xiao.common.util.WorkIdUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author xiaoxiaoping
 * @Date 2020/3/26 16:53
 * @Version 1.0
 */
@Service
public class DiagnosisResultServiceImpl implements DiagnosisResultService {
    @Resource
    private DiagnosisresultMapper diagnosisresultMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(DictEmployee dictEmployee,DiagnosisresultVo diagnosisresultVo) {
        if(diagnosisresultVo.getDiagnosisVoList().size()>0){
            Diagnosisresult diagnosisresult1 = BeanUtil.copyBean(diagnosisresultVo,Diagnosisresult.class);
            diagnosisresult1.setHospid(dictEmployee.getHOSPID());
            diagnosisresultMapper.deleteByEntity(diagnosisresult1);
            for(DiagnosisVo  diagnosisVo:diagnosisresultVo.getDiagnosisVoList()){
                Diagnosisresult diagnosisresult = BeanUtil.copyBean(diagnosisVo,Diagnosisresult.class);
                diagnosisresult.setId(WorkIdUtil.nextId());
                diagnosisresult.setCreaterId(dictEmployee.getEMPID());
                diagnosisresult.setOrgid(diagnosisresultVo.getOrgid());
                diagnosisresult.setEmpidDoct(diagnosisresultVo.getEmpidDoct());
                diagnosisresult.setPatiid(diagnosisresultVo.getPatiid());
                diagnosisresult.setSerialnumber(diagnosisresultVo.getSerialnumber());
                diagnosisresult.setHospid(dictEmployee.getHOSPID());
                diagnosisresultMapper.insertSelective(diagnosisresult);
            }
        }else{
            throw HisExecption.serverErrException("诊断信息不能为空");
        }
    }

    @Override
    public List<Diagnosisresult> getDiagnosis(DictEmployee dictEmployee,GetDiagnosisVo getDiagnosisVo) {
        Diagnosisresult diagnosisresult = BeanUtil.copyBean(getDiagnosisVo,Diagnosisresult.class);
        diagnosisresult.setHospid(dictEmployee.getHOSPID());
        return diagnosisresultMapper.selectByEntity(diagnosisresult);
    }
}
